package cn.edu.leetcode.其他;

public class 删除有序数组中的重复项 {
    public static void main(String[] args) {

        int[] nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};

        System.out.println(removeDuplicates(nums));
    }

    public static int removeDuplicates(int[] nums) {

        int p = 0;
        for (int i = 0; i < nums.length; i++) {
            if (!haveRepetition(nums, p, i)) {
                nums[p] = nums[i];
                p++;
            }
        }
        return p;
    }

    public static boolean haveRepetition(int[] nums, int p, int i) {

        for (p = p - 1; p >= 0; p--) {
            if (nums[i] == nums[p]) {
                return true;
            }
        }
        return false;
    }

}
